import request from '@/utils/request'

export interface Activity {
  id: string
  type: 'create' | 'update' | 'delete' | 'publish' | 'archive' | 'view' | 'like' | 'comment'
  target: string
  targetId: string
  targetTitle?: string
  content: string
  metadata?: any
  createdAt: string
}

export interface ActivitiesResponse {
  success: boolean
  data: {
    activities: Activity[]
    pagination: {
      page: number
      limit: number
      total: number
      pages: number
    }
  }
}

export interface UserStats {
  summary: {
    totalLessonPlans: number
    publishedLessonPlans: number
    draftLessonPlans: number
    archivedLessonPlans: number
    totalViews: number
    totalLikes: number
    uploadedFiles: number
    totalFileSize: number
  }
  charts: {
    monthlyStats: Array<{
      period: string
      count: number
    }>
    subjectStats: Array<{
      subject: string
      count: number
    }>
  }
  recentActivity: {
    recentLessonPlans: Array<{
      id: string
      title: string
      status: string
      createdAt: string
      views: number
      likes: number
    }>
  }
}

export const userApi = {
  // 获取用户活动记录
  getActivities: (params?: { page?: number; limit?: number }) => {
    return request<ActivitiesResponse>({
      url: '/users/activities',
      method: 'get',
      params
    })
  },

  // 获取用户统计数据
  getStats: () => {
    return request<{ success: boolean; data: UserStats }>({
      url: '/users/stats',
      method: 'get'
    })
  },

  // 更新用户资料
  updateProfile: (data: { name?: string; bio?: string }) => {
    return request({
      url: '/users/profile',
      method: 'put',
      data
    })
  },

  // 修改密码
  changePassword: (data: { currentPassword: string; newPassword: string }) => {
    return request({
      url: '/users/change-password',
      method: 'post',
      data
    })
  }
}